//
//  AUEssenceTopicModel.swift
//  Alamofire
//
//  Created by Miss_Special on 2018/4/17.
//  完整模型

import UIKit

class AUEssenceTopicModel: NSObject {
    
    @objc var bookmark: String = ""
    @objc var text: String = ""
    @objc var share_url: String = ""
    @objc var passtime: String = ""
    
    @objc var id: String = ""
    
    @objc var status: Int = 0
    @objc var comment: Int = 0
    @objc var up: Int = 0
    @objc var down: Int = 0
    @objc var forward: Int = 0
    
    @objc var type: String = "" {
        didSet {
            switch type {
            case "video":
                topicType = AUEssenceTopicType.video
            case "image", "gif":
                topicType = AUEssenceTopicType.picture
            case "text":
                topicType = AUEssenceTopicType.joke
            case "audio":
                topicType = AUEssenceTopicType.listen
            default:
                topicType = AUEssenceTopicType.none
            }
        }
    }
    
    var topicType: AUEssenceTopicType = .none
    
    /// 评论
    var top_comments = [AUEssenceTopicCommentModel]()
    /// 用户信息
    var user: AUEssenceTopicUserModel = AUEssenceTopicUserModel(dict: [:])
    /// 图片信息
    var picture = AUEssenceTopicPictureModel(dict: [:])
    /// gif信息
    var picture_gif = AUEssenceTopicGifModel(dict: [:])
    /// 视频信息
    var video = AUEssenceTopicVideoModel(dict: [:])
    
    init(dict: [String: Any]) {
        super.init()
        setValuesForKeys(dict)
        
        if let commentList = dict["top_comments"] as? [[String: Any]] {
            var tempArray = [AUEssenceTopicCommentModel]()
            for dict in commentList {
                tempArray.append(AUEssenceTopicCommentModel(dict: dict))
            }
            top_comments = tempArray
        }
        
        if let userDict = dict["u"] as? [String: Any] {
            user = AUEssenceTopicUserModel(dict: userDict)
        }
        
        if let pictureDict = dict["image"] as? [String: Any] {
            picture = AUEssenceTopicPictureModel(dict: pictureDict)
        }
        
        if let gifDict = dict["gif"] as? [String: Any] {
            picture_gif = AUEssenceTopicGifModel(dict: gifDict)
        }
        
        if let videoDict = dict["video"] as? [String: Any] {
            video = AUEssenceTopicVideoModel(dict: videoDict)
        }
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
}
